<?php

namespace addons\Insurance\common\models;

use addons\Employees\common\models\Employees;
use Yii;

/**
 * This is the model class for table "{{%addon_oa_insurance}}".
 *
 * @property int $id ID
 * @property int $employees_id 员工
 * @property string $amount 金额
 * @property int $pay_time 交纳时间
 * @property int $status 状态
 * @property int $created_at 创建时间
 * @property int $updated_at 修改时间
 */
class Insurance extends \common\models\base\BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%addon_insurance}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['employees_id', 'pay_time'], 'required'],
            [['merchant_id','employees_id', 'status', 'created_at', 'updated_at'], 'integer'],
            [['pay_amount'], 'number'],
            [['pay_time'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'employees_id' => '员工',
            'pay_amount' => '交纳金额',
            'pay_time' => '交纳日期',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }

    /**
     * 关联员工
     *
     * @return \yii\db\ActiveQuery
     */
    public function getEmployees()
    {
        return $this->hasOne(Employees::class, ['id' => 'employees_id']);
    }
    public function beforeSave($insert)
    {
        $this->merchant_id = Yii::$app->user->identity->merchant_id;
        return parent::beforeSave($insert);
    }
}